package com.ruoyi.business.controller;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.entity.GwBooking;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.business.service.IGwBookingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 取号管理Controller
 *
 * @author ruoyi
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/gwBooking")
public class GwBookingController extends BaseController
{
    @Autowired
    private IGwBookingService gwBookingService;

    /**
     * 查询车辆管理列表
     */
    //@PreAuthorize("@ss.hasPermi('com.ruoyi.business:booking:list')")
    @GetMapping("/list")
    public TableDataInfo list(GwBooking gwBooking)
    {
        startPage();
        List<GwBooking> list = gwBookingService.selectGwBookingList(gwBooking);
        return getDataTable(list);
    }
    @GetMapping("/gwBookingList")
    public TableDataInfo gwBookingList(GwBooking gwBooking)
    {
        startPage();
        //自己的
        //gwBooking.setUserId(getUserId());
        gwBooking.setUserId(1L);
        if (gwBooking.getType()==0) {
            startPage();
            List<GwBooking> list = gwBookingService.selectGwBookingList( gwBooking );
            return getDataTable(list);
        }else {
            //最新消息
            startPage();
            gwBooking.setStatus( 1L );
            List<GwBooking> list = gwBookingService.selectGwBookingList( gwBooking );
            return getDataTable(list);
        }
    }

    /**
     * 导出车辆管理列表
     */
    //@PreAuthorize("@ss.hasPermi('com.ruoyi.business:booking:export')")
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwBooking gwBooking)
    {
        List<GwBooking> list = gwBookingService.selectGwBookingList(gwBooking);
        ExcelUtil<GwBooking> util = new ExcelUtil<GwBooking>(GwBooking.class);
        util.exportExcel(response, list, "车辆管理数据");
    }

    /**
     * 获取车辆管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('com.ruoyi.business:booking:query')")
    @GetMapping(value = "/{bookingId}")
    public AjaxResult getInfo(@PathVariable("bookingId") Long bookingId)
    {
        return success(gwBookingService.selectGwBookingByBookingId(bookingId));
    }

    /**
     * 新增车辆管理
     */
    //@PreAuthorize("@ss.hasPermi('com.ruoyi.business:booking:add')")
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwBooking gwBooking)
    {
        if (gwBooking.getArriveDates()!=null){
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate date = LocalDate.parse(gwBooking.getArriveDates(), formatter);
            gwBooking.setArriveDate(DateUtils.toDate(date));
        }
        return toAjax(gwBookingService.insertGwBooking(gwBooking));
    }

    /**
     * 修改车辆管理
     */
    //@PreAuthorize("@ss.hasPermi('com.ruoyi.business:booking:edit')")
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwBooking gwBooking)
    {
        return toAjax(gwBookingService.updateGwBooking(gwBooking));
    }

    /**
     * 删除车辆管理
     */
    //@PreAuthorize("@ss.hasPermi('com.ruoyi.business:booking:remove')")
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bookingIds}")
    public AjaxResult remove(@PathVariable Long[] bookingIds)
    {
        return toAjax(gwBookingService.deleteGwBookingByBookingIds(bookingIds));
    }

    @PutMapping("/notices")
    public AjaxResult notice(@PathVariable Long[] bookingIds)
    {
        return AjaxResult.success(  );
    }
}
